<template>
    <div id="app">
        <Login/>
        <router-view style="padding-bottom: 90px" />
        <Bet/>
        <Bottom/>
    </div>
</template>

<script>
import { loginStatus,getUserInfo } from "@/apis/apis";
import Login from "@/components/login";
import Bottom from "@/components/bottom";
import Bet from "@/components/bet";
import bus from "@/utils/bus";

export default {
  components: {
    Login,
    Bottom,
    Bet,
  },
  methods: {
    async LoginAndInvite() {
      const login = await loginStatus().then(res => res);
      // console.log(login)
      const member = await getUserInfo().then(res => res);
      // console.log(member)
      if (login.login && member.is_pull_new === false && this.$route.name !== 'invite') {
        this.$dialog
          .confirm({
            message: `识别到邀请码${this.$route.query.invite_code}，点击确认跳转到邀请页面领取`
          })
          .then(() => {
            this.$router.push(
              `/invite?invite_code=${this.$route.query.invite_code}`
            );
          });
      } else if (!login.login) {
        this.$dialog
          .confirm({
            message: "你获得一份邀新的抽奖机会，登录之后再领取",
            confirmButtonText: "前往登录"
          })
          .then(res => {
            bus.$emit("show_login_dialog");
          });
      }
    }
  },
  mounted() {
    const code = this.$route.query.invite_code;
    if (code) this.LoginAndInvite();
    this.$store.dispatch('fetchUserLoginStatus')
  }
};
</script>

<style lang="scss">
@import "style/var.scss";

*,
*:before,
*:after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: rgba(255, 0, 0, 0);
}

html,
body {
  width: 100%;
  height: 100%;
  -webkit-touch-callout: none;
  user-select: none;
  padding-bottom: 70px;
}

#app {
  width: 100%;
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: $common_background_color;
}

#nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
